function is_valid = is_l0_schedule_valid(schedule, G, code_map)
    l0_active = zeros(1, 3);
    for i = 1:length(schedule)
        node_id = schedule(i);
        op = G.Nodes.OpCode(node_id); type = G.Nodes.TypeCode(node_id);
        if isequal(op, code_map.op.ALLOC)
            if isequal(type, code_map.type.L0A), l0_active(1)=l0_active(1)+1; end
            if isequal(type, code_map.type.L0B), l0_active(2)=l0_active(2)+1; end
            if isequal(type, code_map.type.L0C), l0_active(3)=l0_active(3)+1; end
            if any(l0_active > 1), is_valid = false; return; end
        elseif isequal(op, code_map.op.FREE)
            if isequal(type, code_map.type.L0A), l0_active(1)=l0_active(1)-1; end
            if isequal(type, code_map.type.L0B), l0_active(2)=l0_active(2)-1; end
            if isequal(type, code_map.type.L0C), l0_active(3)=l0_active(3)-1; end
        end
    end
    is_valid = true;
end
